import { createStore } from 'redux'
const initState = {
    isLogin: false,
    userInfo: {
        phone: '13902518301',
        token: ''
    }
}
function reducer(state=initState, action) {
    let origin = {...state}
    let temp = origin
    for (let k in action.key) {
        if (temp.hasOwnProperty(action.key[k])) {
            if (+k === action.key.length - 1) {
                temp[action.key[k]] = action.value
                return {...origin}
            }
            temp = temp[action.key[k]]
        } else {
            throw new Error(action.key[k]+'属性不存在于对象'+action.key[k-1]+'中')
        }
    }
    return state
}
// 

const store = createStore(reducer)

export const updateState = (data) => {
    store.dispatch({type: 'state', ...data})
}

export default store